#include <string.h>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <vector>
using namespace std;

int pow(int b,int e)
{
	if(e==0)
		return 1;
	int ret=1;
	unsigned int npow = e;
	if(e<0)
		npow = (unsigned int)-e;
	while(npow)
	{
		if(npow&1)
			ret *= b;
		b *= b;
		npow >>= 1;
	}
	return ret;
}


unsigned int process(vector<int> &v)
{
	int n = v.size();
	unsigned int ret=0;
	for(int i=0;i<n;++i)
	{
		ret += v[i]*pow(10,n-1-i);
	}
	return ret;
}

int atoi(const char* str)
{
	if(strlen(str)==0)
		return 0;
	while(*str == ' ')
		str++;

	bool flag = false;
	if(*str == '-')
	{
		flag = true;
		str++;
	}
	if(*str=='+' && flag == false)
		str++;
	if(*str < '0' && *str > '9')
		return 0;
	// vc5Pv6Nc9wP9
	while(*str == '0')
		str++;
	//vector<int> v;
	unsigned long long  ret=0;
	while(*str >= '0' && *str <= '9')
	{
		ret = (ret<<3)+(ret<<1)+(*str-'0'); //goodammmmmm
		// ret<<3 --> ret*2^3 = ret*8
		// ret<<1 --> ret*2
		// ret<<3+ret<<1 ==> ret*10;
		// v.push_back(*str-'0');
		str++;
	}
	//unsigned int ret = process(v);
	if(ret>INT_MAX)
	{
		if(flag)
			return INT_MIN;
		return INT_MAX;
	}

	return (flag) ? -ret : ret;

}

int main()
{
	const char* str = "-3924x8fc";
	cout<<atoi(str)<<endl;
	return 0;
}